package edu.luc.cs.backend;
/* Calendar information   */  //package ididates;
// --------------------   (Copyright 1997, Information Disciplines, Inc.)

//  This pseudo-class:
//     -  collects constants and tables that describe the Gregorian calendar,
//     -  provides certain calendar-related functions that are independent
//        of the Date class and of the representation of Date objects.

//  All members (both data and functions) are static (non-instance) members.

public class CalendarInfo {

  public static final short DAYS_PER_YEAR      =    365;
  public static final short DAYS_PER_4_YEARS   =   1461;
  public static final int   DAYS_PER_100_YEARS =  36524;
  public static final int   DAYS_PER_400_YEARS = 146097;

  public static final byte  DAYS_IN_MONTH []   = {0, 31, 28, 31, 30, 31, 30,
                                                     31, 31, 30, 31, 30, 31};

  public static final short DAYS_BEFORE_MONTH[]= {0,  0, 31, 59, 90,120,151,
                                                    181,212,243,273,304,334,365};

  public static short centuryBreak = 20; //  2-digit year is 19yy if yy >
                                         //                  20yy if yy <=

//  Language-specific names
//  -----------------------

  public static final String  MONTH_NAME[]
    ={"","January", "February", "March"    , "April"  ,  "May"    , "June"   ,
         "July"   , "August"  , "September", "October", "November", "December"};

  public static final String  DAY_NAME[]
    = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};


//  Utility functions
//  -----------------

  public static boolean isLeapYear(int yyyy)
  {return (0 == yyyy % 4) && (!(0 == yyyy % 100) || (0 == yyyy % 400));}

  public static boolean isLegalYMD(int yyyy, int mm, int dd)
  {return mm > 0 &&  mm <= 12
       && dd > 0 && (dd <= DAYS_IN_MONTH [mm]
                     || (dd == 29 && mm == 2 && isLeapYear(yyyy)));
  }

  public static short dayNumber(int yyyy, int mm, int dd)
  {if  (!isLegalYMD(yyyy, mm, dd)) return 0;
   int  ddd = DAYS_BEFORE_MONTH [mm] + dd;
   if  (isLeapYear(yyyy) && mm > 2) ddd++;
   return (short) ddd;
  }

}
